/**
 * Created by 20155322 on 2017/5/4.
 */

import junit.framework.TestCase;
import org.junit.Test;

import java.lang.*;
import java.util.Arrays;

public class ComplexTest extends TestCase {
    Complex c1 = new Complex(0, 3);
    Complex c2 = new Complex(-1, -1);
    Complex c3 = new Complex(2, 1);

    String str = "dangranshixuanzeyuanliangtala";

    String str2 = "dang:ran:shi:xuan:ze:yuan:liang:ta:la";
    //String[] str2sort = str2.split(":");

    String[] str3 = new String[]{"dang", "ran", "shi", "xuan", "ze", "yuan", "liang", "ta", "la"};

    /*public void ArraysTest(String[] str3) {
        Arrays.sort(str3);
        for (int i = 0 ; i<str3.length; i++) {
            System.out.printf("Value = %c%n",str3[i]);
    }
*/
    double str4[] = {5.4, 4.6, 49.2, 9.2, 35.4};
/*
    public void ArraysTest2(double[] str4) {
        Arrays.sort(str4);
    }
*/
    @Test
    public void testgetRealPart() throws Exception {
        assertEquals(-1.0, Complex.getRealPart(-1.0));
        assertEquals(5.0, Complex.getRealPart(5.0));
        assertEquals(0.0, Complex.getRealPart(0.0));
    }

    @Test
    public void testgetImagePart() throws Exception {
        assertEquals(-1.0, Complex.getImagePart(-1.0));
        assertEquals(5.0, Complex.getImagePart(5.0));
        assertEquals(0.0, Complex.getImagePart(0.0));
    }

    @Test
    public void testgetPart() throws Exception {
        assertEquals(4.0, Complex.getImagePart(4.0));
        assertEquals(5.0, Complex.getImagePart(5.0));
        assertEquals(1.0, Complex.getImagePart(1.0));
    }

    @Test
    public void testString_charAt() throws Exception {
        assertEquals('d', Complex.getString_charAt(str,0));
        assertEquals('g', Complex.getString_charAt(str,3));
        assertEquals('n', Complex.getString_charAt(str,6));
    }

    @Test
    public void testString_split() throws Exception {
        assertEquals("dang", Complex.getString_split(str2)[0]);
        assertEquals("yuan", Complex.getString_split(str2)[5]);
        assertEquals("liang", Complex.getString_split(str2)[6]);
    }

    @Test
    public void testgetArrays_sort() throws Exception {
        //ArraysTest(str3);
        assertEquals("dang", Complex.getArrays_sort(str3)[0]);
        assertEquals("ta", Complex.getArrays_sort(str3)[5]);
        assertEquals("xuan", Complex.getArrays_sort(str3)[6]);
    }

    @Test
    public void testgetArrays_binarySearch() throws Exception {
        //ArraysTest2(str4);
        assertEquals(1, Arrays.binarySearch(Complex.getArrays_binarySearch(str4), 5.4));
        assertEquals(0, Arrays.binarySearch(Complex.getArrays_binarySearch(str4), 4.6));
        assertEquals(4, Arrays.binarySearch(Complex.getArrays_binarySearch(str4), 49.2));
    }
 /*
        @Test
        public void testComplexAdd() throws Exception {
            assertEquals("-1.0+2.0i", c1.ComplexAdd(c2).toString());
            assertEquals("2.0+4.0i", c1.ComplexAdd(c3).toString());
            assertEquals("1.0", c2.ComplexAdd(c3).toString());
        }
        @Test
        public void testComplexSub() throws Exception {
            assertEquals("1.0+4.0i", c1.ComplexSub(c2).toString());
            assertEquals("-2.0+2.0i", c1.ComplexSub(c3).toString());
            assertEquals("-3.0 -2.0i", c2.ComplexSub(c3).toString());
        }
        @Test
        public void testComplexMulti() throws Exception {
            assertEquals("3.0 -3.0i", c1.ComplexMulti(c2).toString());
            assertEquals("-3.0+6.0i", c1.ComplexMulti(c3).toString());
            assertEquals("-1.0 -3.0i", c2.ComplexMulti(c3).toString());
        }
        @Test
        public void testComplexComplexDiv() throws Exception {
            assertEquals("-1.5 -1.5i", c1.ComplexDiv(c2).toString());
            assertEquals("1.2+0.6i", c1.ComplexDiv(c3).toString());
            assertEquals("-0.6 -0.6i", c2.ComplexDiv(c3).toString());
            }
            */

}
